#ifndef MESHDRAW2SIDE_HPP
#define MESHDRAW2SIDE_HPP

#include "Color.hpp"
#include "Mat4.hpp"
#include "Mesh.hpp"

class MeshDraw2Side
{
public:

   static const float sMaterialColors[18][3];

   MeshDraw2Side();

   void EnableMaterials(bool aUseMaterials) { mUseMaterials = aUseMaterials; }

   void DrawSection(int aSection, float aAlpha = 1.0);

   int  GetSectionCount() { return mSections.size(); }

   //int  GetSectionMaterial(int aSection) { return mSections[aSection].mMaterialIndex; }
   void Draw(float aAlpha = 1.0);

   void SetMesh(const Mesh& aMesh);

   const Mesh& GetMesh() { return *mMeshPtr; }

   void BindVertexBuffer();

   void BindIndexBuffer();

   void ReleaseVertexBuffer();

   void ReleaseIndexBuffer();

private:

   void DrawSectionP(int aSection, float aAlpha = 1.0f);

   void LoadVBO();

   void UnbindVBO();

   void PrepareBuffers();

   Mesh* mMeshPtr;
#pragma pack(push, 1)
   struct Vertex
   {
      Vec3  p;
      Vec3  n;
   };
#pragma pack(pop)
   Color GetMaterialColor(int aMaterial);
   struct MaterialSection
   {
      int   mOffset;
      int   mFaceCount;
      RegionInterface   mInterface;
      Color mColor;
      Color mColor2;
   };
   typedef std::vector<Vertex> VertexList;
   bool mUseMaterials;
   VertexList                 mVertices;
   std::vector<int>  mIndices;
   std::vector<MaterialSection>  mSections;

   unsigned int mVBO_Buffers[2];

   std::vector<Vec3> mCentroids;
};
#endif
